<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <router-link to="/redact_abt/redact/form">
        <el-button
          type="primary"
          icon="el-icon-plus"
          style="margin-left:0px"
        >添加</el-button>
      </router-link>
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column prop="title" label="活动名称" width="150" />
        <el-table-column align="center" prop="money_type" label="类型" width="150">
          <template slot-scope="scope">
            {{money_type_arr[scope.row.money_type]}}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="thumb" label="海报" width="150">
          <template slot-scope="scope">
            <el-popover
            placement="right"
            trigger="hover">
            <img :src="scope.row.thumb" class="imgStyle" style="max-height: 300px;max-width: 750px"/>
            <img slot="reference" :src="scope.row.thumb" style="max-height: 50px;max-width: 150px">
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="start_time" label="开始日期" width="180" />
        <el-table-column prop="end_time" label="结束日期" width="180" />
        <el-table-column align="center" prop="status" label="状态" width="150">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status === 1 ? 'primary' : scope.row.status === 2 ?'error' :'success'">{{status_arr[scope.row.status]}}</el-tag>
            
            <el-button
            type="primary"
              v-if="scope.row.status ==0"
              size="mini"
              @click="pay_status(scope.row)"
            >支付</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="bonus" label="红包总额" width="100" />
        <el-table-column prop="bonus_now" label="剩余" width="150" />
        <el-table-column prop="share_num" label="分享数" width="150" />
        <el-table-column align="center" prop="qrcode" label="分享码" width="150">
          <template slot-scope="scope">
            <el-popover
            placement="right"
            trigger="hover">
            <img :src="scope.row.qrcode" class="imgStyle" style="max-height: 300px;max-width: 750px"/>
            <img slot="reference" :src="scope.row.qrcode" style="max-height: 50px;max-width: 150px">
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          prop="telephone"
          fixed="right"
          width="240"
          label="操作"
        >
          <template slot-scope="scope">
            <router-link :to="'/redact_abt/redact/form?id=' + scope.row.id">
              <el-button type="primary" icon="el-icon-edit" />
            </router-link>
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="onDel(scope.row)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
     layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'redact_index',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入店铺名', field: 'title', val: '' }
      ],
      dateTime: '',
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      money_type_arr: [],
      status_arr: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  activated(){
    // if(this.$getUpdate()){
      this.onSearch()
    // }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    pay_status(row){
      this.$msg_confirm_show('是否支付 '+row.bonus+' 以开启红包活动','支付','true').then((e) => {
        this.get('/shop/RedAct/pay', {id:row.id}, 'POST').then((e)=>{
          this.onSearch()
          this.$msg_ok('success','支付成功')
        })
      })
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/shop/RedAct/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.money_type_arr = e.money_type_arr
        this.status_arr = e.status_arr
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
        
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
     // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, 'RedAct').then(e => {
        e ? this.onSearch() : ''
      })
    },
    // 删除
    onDel(row) {
      if(row.status==1){
        this.$msg_ok('error','活动未结束,不能删除')
        return
      }
      this.$confirm('是否删除该记录', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.get('/shop/RedAct/del?id=' + row.id, this.form, 'POST').then(e => {
          this.onSearch()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
